package xyf.p11.other.prepoststatistics;

/**
 * ClassName: P0053_MaxSubArray
 * Description:
 * Author: xyf
 * Date: 9/9/22 10:17 AM
 * Version: 1.0
 **/
public class P0053_MaxSubArray
{
    public int maxSubArray(int[] nums)
    {
        int[] dp = new int[nums.length];
        dp[0] = nums[0];
        int max = nums[0];
        for (int i = 1; i < nums.length; i++)
        {
            if (dp[i - 1] < 0)
            {
                dp[i] = nums[i];
            }
            else
            {
                dp[i] = dp[i - 1] + nums[i];
            }
            max = Math.max(max, dp[i]);
        }
        return max;
    }
}
